﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace NexTrackDesktop.ViewModels
{
    /// <summary>
    /// This class is used to link view events to ViewModels
    /// </summary>
    class DelegateCommand : ICommand
    {
        Action _executeAction;
        Func<bool> _canExecuteFunction;

        public DelegateCommand(Action ExecuteAction, Func<bool> CanExecuteFunction)
        {
            _executeAction = ExecuteAction;
            _canExecuteFunction = CanExecuteFunction;
        }

        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }

        public bool CanExecute(object parameter)
        {
            return _canExecuteFunction();
        }

        public void Execute(object parameter)
        {
            _executeAction();
        }
    }
}
